package com.huaxiafinance.management.service.impl;

import com.huaxiafinance.management.dto.request.QuerySignRecordDto;
import com.huaxiafinance.management.mapper.UserSignRecordMapper;
import com.huaxiafinance.management.model.UserSignRecord;
import com.huaxiafinance.management.service.UserSignRecordService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 签到管理service实现类
 */
@Service
public class UserSignRecordServiceImpl implements UserSignRecordService {

    private static final Logger logger = Logger.getLogger(UserSignRecordServiceImpl.class);

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    private UserSignRecordMapper userSignRecordMapper;

    /**
     * 按指定条件查询签到记录
     * @param dto
     * @return
     */
    @Override
    public List<UserSignRecord> selectSignRecordList(QuerySignRecordDto dto) {
        dto.setPage(dto.getPage() == null ? null : (dto.getPage()-1) * dto.getRows());

        return userSignRecordMapper.selectSignRecordList(dto);
    }

    /**
     * 查询指定条件的签到记录条数
     * @param dto
     * @return
     */
    @Override
    public int countSignRecord(QuerySignRecordDto dto) {
        try {
            return userSignRecordMapper.countSignRecord(dto);
        }catch (Exception e){
            logger.error(e.getMessage(), e);
        }
        return 0;
    }
}
